home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / mobile / fma-2.0-stable-setup.exe / {app} / source / uAddToPhonebook.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2004-09-08  |  3.8 KB  |  152 lines

  1. unit uAddToPhonebook;
  2.  
  3. {
  4. *******************************************************************************
  5. * Descriptions: Add Contact to Phonebook
  6. * $Source: /cvsroot/fma/fma/uAddToPhonebook.pas,v $
  7. * $Locker:  $
  8. *
  9. * Todo:
  10. *
  11. * Change Log:
  12. * $Log: uAddToPhonebook.pas,v $
  13. * Revision 1.3.6.1  2004/09/08 20:21:19  lordlarry
  14. * Added Exception.Message to the Exception Details Log
  15. *
  16. * Revision 1.3  2004/07/07 08:10:46  z_stoichev
  17. * Common Wizard Image usage
  18. *
  19. * Revision 1.2  2004/06/30 15:28:26  z_stoichev
  20. * GUI improvements
  21. *
  22. * Revision 1.1  2004/06/30 14:05:20  z_stoichev
  23. * Initial checkin.
  24. *
  25. *
  26. }
  27.  
  28. interface
  29.  
  30. uses
  31.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  32.   Dialogs, StdCtrls, TntStdCtrls, ExtCtrls, uSyncPhonebook, VirtualTrees;
  33.  
  34. type
  35.   TfrmAddContact = class(TForm)
  36.     Bevel1: TBevel;
  37.     btnOk: TButton;
  38.     btnCancel: TButton;
  39.     Panel1: TPanel;
  40.     Image1: TImage;
  41.     Label4: TLabel;
  42.     lbProductName: TLabel;
  43.     Button3: TButton;
  44.     Label1: TLabel;
  45.     lblNumber: TLabel;
  46.     edContact: TTntEdit;
  47.     btnSelect: TButton;
  48.     RadioButton1: TRadioButton;
  49.     RadioButton2: TRadioButton;
  50.     rgPhoneType: TRadioGroup;
  51.     procedure btnSelectClick(Sender: TObject);
  52.     procedure RadioButtonClick(Sender: TObject);
  53.     procedure FormCreate(Sender: TObject);
  54.     procedure btnOkClick(Sender: TObject);
  55.   private
  56.     procedure Set_NewNumber(const Value: string);
  57.     { Private declarations }
  58.   public
  59.     { Public declarations }
  60.     function GetSelectedContactData: PContactData;
  61.     property NewNumber: string write Set_NewNumber;
  62.   end;
  63.  
  64. var
  65.   frmAddContact: TfrmAddContact;
  66.  
  67. implementation
  68.  
  69. uses uGetContact, Unit1;
  70.  
  71. {$R *.dfm}
  72.  
  73. procedure TfrmAddContact.btnSelectClick(Sender: TObject);
  74. begin
  75.   with TfrmGetContact.Create(nil) do
  76.     try
  77.       SelContacts := edContact.Text;
  78.       if ShowModal = mrOk then begin
  79.         edContact.Text := SelContacts;
  80.         edContact.SetFocus;
  81.       end;
  82.     finally
  83.       Free;
  84.     end;
  85. end;
  86.  
  87. procedure TfrmAddContact.RadioButtonClick(Sender: TObject);
  88. begin
  89.   edContact.Enabled := RadioButton2.Checked;
  90.   if edContact.Enabled then
  91.     edContact.Color := clWindow
  92.   else
  93.     edContact.Color := clBtnFace;
  94.   rgPhoneType.Enabled := edContact.Enabled;
  95.   btnSelect.Enabled := edContact.Enabled;
  96. end;
  97.  
  98. procedure TfrmAddContact.FormCreate(Sender: TObject);
  99. begin
  100. {$IFNDEF VER150}
  101.   Form1.ThemeManager1.CollectForms(Self);
  102. {$ENDIF}
  103.   Image1.Picture.Assign(Form1.FmaWebUpdate1.Picture);
  104.   lblNumber.Font.Style := lblNumber.Font.Style + [fsBold];
  105. end;
  106.  
  107. procedure TfrmAddContact.btnOkClick(Sender: TObject);
  108. var
  109.   contact: PContactData;
  110.   Number: string;
  111. begin
  112.   if RadioButton1.Checked then
  113.     ModalResult := mrOk
  114.   else begin
  115.     contact := GetSelectedContactData;
  116.     if contact = nil then begin
  117.       ShowMessage('You have to select an existing contact first');
  118.       Exit;
  119.     end;
  120.     if Assigned(contact) then begin
  121.       case rgPhoneType.ItemIndex of
  122.         0: Number := contact^.cell;
  123.         1: Number := contact^.work;
  124.         2: Number := contact^.home;
  125.         3: Number := contact^.fax;
  126.         4: Number := contact^.other;
  127.       end;
  128.       if (Number = '') or (MessageDlg('This phone type position is already taken by "'+Number+'". Overwrite it?',
  129.           mtConfirmation,[mbYes,mbNo],0) = mrYes) then
  130.           ModalResult := mrOk;
  131.     end;
  132.   end;
  133. end;
  134.  
  135. function TfrmAddContact.GetSelectedContactData: PContactData;
  136. var
  137.   Node: PVirtualNode;
  138. begin
  139.   Result := nil;
  140.   if RadioButton2.Checked then
  141.     if Form1.frmSyncPhonebook.FindContact(Form1.ExtractContact(edContact.Text),Node) then begin
  142.       Result := Form1.frmSyncPhonebook.ListContacts.GetNodeData(Node);
  143.     end;
  144. end;
  145.  
  146. procedure TfrmAddContact.Set_NewNumber(const Value: string);
  147. begin
  148.   lblNumber.Caption := Value;
  149. end;
  150.  
  151. end.
  152.